package cloud.tianai.ram.policy.server.condition.impl.handler;

import cloud.tianai.ram.policy.common.model.dto.Action;
import cloud.tianai.ram.policy.common.handler.AbstractConditionHandler;
import cloud.tianai.ram.policy.common.model.dto.Condition;
import cloud.tianai.ram.policy.common.handler.ConditionHandlerManager;
import cloud.tianai.ram.policy.common.model.dto.TypeDefinition;

/**
 * @Author: 天爱有情
 * @date 2022/3/24 14:21
 * @Description 条件组合器  并且
 */
public class AndConditionHandler extends AbstractConditionHandler {

    public AndConditionHandler() {
        addTypeDefinition(new TypeDefinition("and", "并且组合器"));
    }

    @Override
    public boolean match(Condition condition, ConditionHandlerManager conditionHandlerManager, Action action) {
        for (Condition child : condition.getChildren()) {
            if (conditionHandlerManager.match(child, action).isDeny()) {
                return false;
            }
        }
        return true;
    }
}
